package zero.tech.games.gate.hot;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import zero.tech.games.common.RedisConsts;
import zero.tech.games.entity.games.CfMarquee;
import zero.tech.games.entity.games.CfServer;
import zero.tech.games.gate.mapper.CfMarqueeMapper;
import zero.tech.games.gate.mapper.CfServerMapper;
import zero.tech.redis.cache.RedisUtil;

@Component
public class CfUtil {
	@Autowired
	private RedisUtil redisUtil;
	@Autowired
	private CfServerMapper cfServerMapper;
	@Autowired
	private CfMarqueeMapper cfMarqueeMapper;
	public CfServer getCfServer(int game_id) {
		CfServer cfServer=(CfServer) redisUtil.get(RedisConsts.HOT_CFSERVER+game_id);
		if(cfServer==null) {
			cfServer=cfServerMapper.getCfServer(game_id);
			redisUtil.set(RedisConsts.HOT_CFSERVER+game_id, cfServer,2*60*60);
		}
		return cfServer;
	}
	@SuppressWarnings("unchecked")
	public List<CfMarquee> loadHotMarquees() {
		List<CfMarquee> list=(List<CfMarquee>) redisUtil.get(RedisConsts.HOT_CFMARQUEE);
		if(list==null) {
			list=cfMarqueeMapper.getAllCfMarquees();
			if(list!=null) {
				redisUtil.set(RedisConsts.HOT_CFMARQUEE, list,10*60);
			}
		}
		return list;
	}

}
